let http = require('../../../utils/api.js');
import {
    myHttps
} from '../../../utils/util.js';
Page({
    data: {
        items: [], //订阅主题的用户列表数据
        userId:'',//userId
        page:1,
        size:10,
    },

    onLoad: function (e) {
        this.setData({
            userId:wx.getStorageSync('userId')
        })
        this.FollowThemeList(this.data.userId,1,10)
    },
    // 关注 接口
    FollowThemeList(id,page,size) {
        let url = http.api.followMediaList + id + '/media' + '?page=' + page + '&size=' + size;
        var that = this;
        myHttps({
            url: url,
            method: "GET",
        }).then(res => {
            // console.log(res)
            if (res.code == 1) {
                that.setData({
                    items: res.data.content
                });
                wx.setNavigationBarTitle({
                    title: '我的关注' //页面标题为路由参数
                })
            }
        }).catch(err => { })
    },
    // 关注媒体
    mediaFollow(e) {
        var that = this
        // console.log(e.currentTarget.dataset.id)
        var id = e.currentTarget.dataset.id
        var index = e.currentTarget.dataset.index
        console.log(index)
        let url = http.api.mediaFollow + id + '/fav';
        myHttps({
            url: url,
            method: "POST"
        }).then(res => {
            if (res.code == 1) {
                that.data.items[index].followed = true
                that.setData({
                    items: that.data.items,
                    hiddenLoading: true
                })
            }
        }).catch(err => { })
    },
    // 取消关注媒体
    canclegz(e) {
        var that = this
        // console.log(e.currentTarget.dataset.id)
        let id = e.currentTarget.dataset.id
        let index = e.currentTarget.dataset.index
        // console.log(index)
        let url = http.api.mediaFollow + id + '/fav';
        myHttps({
            url: url,
            method: "DELETE"
        }).then(res => {
            if (res.code == 1) {
                that.data.items[index].followed = false
                that.setData({
                    items: that.data.items,
                    hiddenLoading: true
                })
            }
        }).catch(err => { })
    },
    //下拉刷新
    onPullDownRefresh: function () {
        //下拉三个点消失
        wx.stopPullDownRefresh();
        this.setData({
            List: [],
            size: 10,
            page: 1,
            hiddenLoading: false
        })
        this.FollowThemeList(this.data.userId, this.data.page, this.data.size);
    },
    // 上拉加载数据
    onReachBottom: function () {
        this.setData({
            size: 10,
            page: this.data.page + 1,
            hiddenLoading: false
        })
        this.FollowThemeList(this.data.userId, this.data.page, this.data.size);
    },
    // 跳转到媒体主页
    goReview (e) {
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '../../mediaHome/mediaHome?id=' + id,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
})